var express = require("express");
var router = express.Router();
const { uploadFiles } = require("../utils/handleFiles");

//图片上传
router.post("/uploadImages", function (req, res, next) {
  // 图片上传
  const uploadImages = uploadFiles({
    // 图片上传成功后的存储路径
    dir: "./public/assets"
    // key: 'file',
    // size: 1000
  });
  uploadImages(req, res, (error) => {
    if (error) {
      console.log("图片上传失败", error);
    } else {
      console.log("图片上传成功");
      // 输出上传成功后的图片信息
      console.log(req.files);
      res.send({
        message: "图片上传成功",
        code: 200,
        data: "./assets/" + req.files[0].filename
      });
    }
  });
});

module.exports = router;
